You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
import { users } from "drizzle-pkg/lib/schema/auth";
|
|
import { and, eq } from "drizzle-orm";
|
|
import { getPublicHubBySlug } from "#server/service/public-hub";
|
|
import { parseSocialLinksJson } from "#server/service/profile";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const publicSlug = event.context.params?.publicSlug;
|
|
if (!publicSlug || typeof publicSlug !== "string") {
|
|
throw createError({ statusCode: 400, statusMessage: "无效主页" });
|
|
}
|
|
|
|
const [owner] = await dbGlobal
|
|
.select()
|
|
.from(users)
|
|
.where(and(eq(users.publicSlug, publicSlug), eq(users.status, "active")))
|
|
.limit(1);
|
|
|
|
if (!owner) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
|
|
const links = parseSocialLinksJson(owner.socialLinksJson).filter((l) => l.visibility === "public");
|
|
|
|
const hub = await getPublicHubBySlug(publicSlug);
|
|
|
|
const payload: {
|
|
user: {
|
|
publicSlug: string | null;
|
|
nickname: string | null;
|
|
avatar: string | null;
|
|
};
|
|
bio: { markdown: string | null } | null;
|
|
links: typeof links;
|
|
modules: Awaited<ReturnType<typeof getPublicHubBySlug>>["modules"];
|
|
posts: Awaited<ReturnType<typeof getPublicHubBySlug>>["posts"];
|
|
timeline: Awaited<ReturnType<typeof getPublicHubBySlug>>["timeline"];
|
|
rssItems: Awaited<ReturnType<typeof getPublicHubBySlug>>["rssItems"];
|
|
} = {
|
|
user: {
|
|
publicSlug: owner.publicSlug,
|
|
nickname: owner.nickname,
|
|
avatar: owner.avatarVisibility === "public" ? owner.avatar : null,
|
|
},
|
|
bio: null,
|
|
links,
|
|
modules: hub.modules,
|
|
posts: hub.posts,
|
|
timeline: hub.timeline,
|
|
rssItems: hub.rssItems,
|
|
};
|
|
|
|
if (owner.bioVisibility === "public" && owner.bioMarkdown) {
|
|
payload.bio = { markdown: owner.bioMarkdown };
|
|
}
|
|
|
|
return R.success(payload);
|
|
});
|
|
|